package com.aaa.mbs.controller;

import com.aaa.common.constants.ReturnStatus;
import com.aaa.common.util.Result;
import com.aaa.mbs.entity.MemberLevel;
import com.aaa.mbs.entity.Order;
import com.aaa.mbs.service.OrderService;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;
import java.util.Map;

/**
 * (Order)表控制层
 *
 * @author makejava
 * @since 2020-12-05 14:35:49
 */
@RestController
@RequestMapping("order")
public class OrderController {
    /**
     * 服务对象
     */
    @Resource
    private OrderService orderService;

    private Logger logger = LoggerFactory.getLogger(OrderController.class);

    /**
     * 通过主键查询单条数据
     *
     * @param id 主键
     * @return 单条数据
     */
    @GetMapping("selectOne")
    @ApiOperation("通过主键查询单条数据")
    public Order selectOne(Integer id) {
        return this.orderService.queryById(id);
    }

    /**
     * 查询指定行数据进行分页
     *
     * @param pageNo      查询起始位置
     * @param pageSize    查询条数
     * @param order
     * @return Result ---- Result.getData() 对象列表
     */
    @PostMapping("queryAllByParam")
    public Result queryAllByParam(@RequestParam("pageNo") Integer pageNo,@RequestParam("pageSize") Integer pageSize,@RequestBody Order order) {

        System.out.println("这是controller层========================================="+pageNo+"这是controller层========================================="+pageSize);
        return this.orderService.queryAllByParam(pageNo, pageSize, order);
    }

    /**
     * 查询所有分页加条件查询
     *
     * @param order    实体
     * @return Result
     */
    @PostMapping("queryAll")
    @ApiOperation("查询所有")
    public List<Order> queryAll(@RequestBody Order order) {
        logger.info("会员ID"+order.getClientId());
        System.out.println(this.orderService.queryAll(order));
        return this.orderService.queryAll(order);
    }

    /**
     * 根据ID删除
     *
     * @param id id
     * @return Result
     */
    @DeleteMapping("deleteById")
    @ApiOperation("根据ID删除")
    public Result deleteById(Integer id) {
        return new Result(ReturnStatus.SUCCESS.getReturnCode(),
                ReturnStatus.SUCCESS.getReturnMsg(), this.orderService.deleteById(id));
    }

    /**
     * 更新
     *
     * @param @param order 实例对象
     * @return Result
     */
    @PutMapping("update")
    @ApiOperation("更新")
    public Result update(@ApiParam("更新json数据") @RequestBody Order order) {
        return new Result(ReturnStatus.SUCCESS.getReturnCode(),
                ReturnStatus.SUCCESS.getReturnMsg(), this.orderService.update(order));
    }

    /**
     * 添加
     *
     * @param @param order 实例对象
     * @return Result
     */
    @PostMapping("insert")
    @ApiOperation("添加")
    public Result insert(@ApiParam("添加json数据") @RequestBody Order order) {
        return new Result(ReturnStatus.SUCCESS.getReturnCode(),
                ReturnStatus.SUCCESS.getReturnMsg(), this.orderService.insert(order));
    }
}